home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 4.9 KB | 196 lines | [TEXT/MPS ] |
- /*
- File: UApplicationSecondStomach.cp
-
- Contains: *** put contents here ***
-
- Written by: Steve Datnow
-
- Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 8/18/93 SLD Change signature
- 1/7/92 SLD Created
-
- To Do:
- */
-
-
-
- #ifndef __UAPPLICATIONSecondStomach__
- #include "UApplicationSecondStomach.h"
- #endif
-
- #ifndef __UDOCUMENTSecondStomach__
- #include "UDocumentSecondStomach.h"
- #endif
-
- #ifndef __UViewStatusInfo__
- #include "UViewStatusInfo.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UGLOBALSSecondStomach__
- #include "UGlobalsSecondStomach.h"
- #endif
-
- #ifndef __PPCTOOLBOX__
- #include "PPCToolBox.h"
- #endif
-
- /****************************** Constants ******************************/
-
- const OSType kSignature = 'SS01'; // Application signature
- const long cUpdateMonitor = 1000;
- const long cAreYouStillAlive = 1001;
-
- // const CommandNumber cCommandHandledByApplication = 400;
-
- /************************** TSSApplicaton **********************/
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AInit
-
- pascal void TApplicationSecondStomach::IApplicationSecondStomach()
- {
- this->IApplication(kFileType,kSignature);
- fLaunchWithNewDocument = FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal TDocument* TApplicationSecondStomach::DoMakeDocument(CommandNumber /* itsCommandNumber */,
- TFile* itsFile) // Override
- {
- TDocumentSecondStomach* aDocument = new TDocumentSecondStomach;
-
- FailInfo fi;
- if (fi.Try())
- {
- aDocument->IDocumentSecondStomach(itsFile,kSignature);
- fi.Success();
- }
- else
- {
- aDocument = (TDocumentSecondStomach*)FreeIfObject(aDocument);
- fi.ReSignal();
- }
-
- return aDocument;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- OSErr GetTargetAddress (Str255& myPrompt, Str255& myAppStr, PortInfoRec& myPortInfo, AEAddressDesc& targetAddress,TargetID& toTargetID)
-
- {
- OSErr myErr;
-
- myErr = PPCBrowser((ConstStr255Param) myPrompt,(ConstStr255Param) myAppStr, FALSE,toTargetID.location,myPortInfo, nil, "");
-
- if (myErr == noErr)
- {
- toTargetID.name = myPortInfo.name;
- return AECreateDesc(typeTargetID,(Ptr) &toTargetID, sizeof(toTargetID), targetAddress);
- }
- else
- return myErr;
- }
-
- pascal void TApplicationSecondStomach::DoMenuCommand(CommandNumber aCommandNumber) // Override
- {
- switch (aCommandNumber)
- {
- default:
- inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TApplicationSecondStomach::DoSetupMenus() // Override
- {
- inherited::DoSetupMenus(); // Always call the inherited method first
-
- // Enable(cCommandHandledByApplication,TRUE);
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal Boolean CompareSessionID(TObject* item, void* staticLink) {
- TDocumentSecondStomach* theDoc = (TDocumentSecondStomach*) item;
- if (theDoc->GetSessionID() == (long) staticLink)
- return TRUE;
- else
- return FALSE;
- }
-
- pascal void TApplicationSecondStomach::DoAppleCommand(CommandNumber aCommandNumber,
- const AppleEvent& message,
- const AppleEvent& reply)
- {
- TAppleEvent* theMessage;
- TAppleEvent* theReply;
- long sessionID;
- TDocumentSecondStomach * myDoc;
-
- switch (aCommandNumber)
- {
- case cUpdateMonitor:
- {
- FailInfo fi;
- if (fi.Try())
- {
- theMessage = new TAppleEvent;
- theMessage->InitializeFromMessage(message, FALSE);
-
- sessionID = theMessage->ReadLong('SSID'); // Which document is it destined for ?
- if (fDocumentList)
- myDoc = (TDocumentSecondStomach *) fDocumentList->FirstThat(&CompareSessionID, (void*) sessionID);
-
- if (myDoc)
- myDoc->HandleStatusInfo(theMessage);
-
- theMessage = (TAppleEvent *)FreeIfObject(theMessage);
- fi.Success();
- }
- else // Recover
- {
- theMessage = (TAppleEvent *)FreeIfObject(theMessage);
- fi.ReSignal();
- }
- }
- break;
- case cAreYouStillAlive:
- {
- theMessage = new TAppleEvent;
- theMessage->InitializeFromMessage(message, FALSE);
- theReply = new TAppleEvent;
- theReply->InitializeFromMessage(reply, FALSE);
- sessionID = theMessage->ReadLong('SSID');
- if (fDocumentList)
- myDoc = (TDocumentSecondStomach *) fDocumentList->FirstThat(&CompareSessionID, (void*) sessionID);
-
- if (myDoc == nil)
- sessionID = -1;
-
- theReply->WriteLong('SSID',sessionID);
- theReply->Send();
-
- theMessage = (TAppleEvent *)FreeIfObject(theMessage);
- theReply = (TAppleEvent *)FreeIfObject(theReply);
- }
- break;
- default:
- inherited::DoAppleCommand(aCommandNumber, message, reply);
- break;
- }
- }
-